package com.muyu.danmo.service.impl;

import com.muyu.common.core.domain.Result;
import com.muyu.danmo.domain.DanmoPrintingLikes;
import com.muyu.danmo.mapper.DanmoPrintingLikesMapper;
import com.muyu.danmo.service.IDanmoPrintingLikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 印刷出版点赞Service业务层处理
 *
 * @author yangle
 * @date 2024-10-15
 */
@Service
public class DanmoPrintingLikesServiceImpl implements IDanmoPrintingLikesService
{
    @Autowired
    private DanmoPrintingLikesMapper danmoPrintingLikesMapper;

    /**
     * 查询印刷出版点赞
     *
     * @param id 印刷出版点赞主键
     * @return 印刷出版点赞
     */
    @Override
    public DanmoPrintingLikes selectDanmoPrintingLikesById(Long id)
    {
        return danmoPrintingLikesMapper.selectDanmoPrintingLikesById(id);
    }

    /**
     * 查询印刷出版点赞列表
     *
     * @param danmoPrintingLikes 印刷出版点赞
     * @return 印刷出版点赞
     */
    @Override
    public List<DanmoPrintingLikes> selectDanmoPrintingLikesList(DanmoPrintingLikes danmoPrintingLikes)
    {
        return danmoPrintingLikesMapper.selectDanmoPrintingLikesList(danmoPrintingLikes);
    }

    /**
     * 新增印刷出版点赞
     *
     * @param danmoPrintingLikes 印刷出版点赞
     * @return 结果
     */
    @Override
    public int insertDanmoPrintingLikes(DanmoPrintingLikes danmoPrintingLikes)
    {
        return danmoPrintingLikesMapper.insertDanmoPrintingLikes(danmoPrintingLikes);
    }

    /**
     * 修改印刷出版点赞
     *
     * @param danmoPrintingLikes 印刷出版点赞
     * @return 结果
     */
    @Override
    public int updateDanmoPrintingLikes(DanmoPrintingLikes danmoPrintingLikes)
    {
        return danmoPrintingLikesMapper.updateDanmoPrintingLikes(danmoPrintingLikes);
    }

    /**
     * 批量删除印刷出版点赞
     *
     * @param ids 需要删除的印刷出版点赞主键
     * @return 结果
     */
    @Override
    public int deleteDanmoPrintingLikesByIds(Long[] ids)
    {
        return danmoPrintingLikesMapper.deleteDanmoPrintingLikesByIds(ids);
    }

    /**
     * 删除印刷出版点赞信息
     *
     * @param id 印刷出版点赞主键
     * @return 结果
     */
    @Override
    public int deleteDanmoPrintingLikesById(Long id)
    {
        return danmoPrintingLikesMapper.deleteDanmoPrintingLikesById(id);
    }

    @Override
    public Result likeTrainingClass(Long userId, Long printingMessageId) {
        if (danmoPrintingLikesMapper.existsByUserIdAndPrintingClassId(userId, printingMessageId)) {
            return Result.success( printingMessageId,"用户已点赞");
        }
        DanmoPrintingLikes danmoPrintingLikes = new DanmoPrintingLikes();
        danmoPrintingLikes.setUserId(userId);
        danmoPrintingLikes.setPrintingMessageId(printingMessageId);
        insertDanmoPrintingLikes(danmoPrintingLikes);
        danmoPrintingLikesMapper.updateAmountPraise(printingMessageId);

        return Result.success(printingMessageId,"点赞成功");
    }
}
